import Vue from 'vue'
import store from '../store'
import VueRouter from 'vue-router'

// 登录注册
const LoginOuter = () => import('views/Login/LoginOuter.vue')
// tabbar
const Home = () => import('views/Home/Home.vue')
// 文件
const DocumentManage = () => import('views/DocumentManage/DocumentManage.vue')
const Recent = () => import('views/DocumentManage/Recent.vue')
const Personal = () => import('views/DocumentManage/Personal.vue')
const Department = () => import('views/DocumentManage/Department.vue')
const Group = () => import('views/DocumentManage/Group.vue')
const Public = () => import('views/DocumentManage/Public.vue')
const Examine = () => import('views/DocumentManage/Examine.vue')
const Recycle = () => import('views/DocumentManage/Recycle.vue')

// 收藏
const FavouriteTree = () => import('views/FavouriteTree/FavouriteTree.vue')
const FavouriteTreeMenu = () => import('views/FavouriteTree/FavouriteTreeMenu.vue')
const FavouriteTreeList = () => import('views/FavouriteTree/FavouriteTreeList.vue')

// 知识库
const KnowledgeTree = () => import('views/KnowledgeTree/KnowledgeTree.vue')
const KnowledgeTreeMenu = () => import('views/KnowledgeTree/KnowledgeTreeMenu.vue')
const KnowledgeTreeList = () => import('views/KnowledgeTree/KnowledgeTreeList.vue')

// 分享
const ShareView = () => import('views/Share/ShareView.vue')
const Share = () => import('views/Share/Share.vue')
const MyShare = () => import('views/Share/MyShare.vue')
const FriendShare = () => import('views/Share/FriendShare.vue')


// 我的
const MyView = () => import('views/My/MyView.vue')
const My = () => import('views/My/My.vue')
const MyDetails = () => import('views/My/MyDetails.vue')
const about = () => import('views/My/about.vue')


// 公共
const Details = () => import('components/public/Details.vue')
const Collection = () => import('components/public/Collection.vue')
const AddKnowledge = () => import('components/public/AddKnowledge.vue')
const Search = () => import('components/public/Search.vue')


VueRouter.prototype.goBack = function () {
  this.isBack = true
  window.history.go(-1)
}

VueRouter.prototype.go = function () {
  this.isBack = true
  window.history.go(-1)
}


Vue.use(VueRouter)

  const routes = [
    {
      path: '/',
      redirect: '/Login'
    },
    {
      path: '/Login',
      name: 'LoginOuter',
      component: LoginOuter
    },
    {
      path: '/Home',
      name: 'Home',
      component: Home,
      redirect: '/DocumentManage',
      children: [
        {
          path: '/DocumentManage',
          name: 'DocumentManage',
          component: DocumentManage,
          redirect: '/Recent',
          meta: {title: '文件'},
          children: [
            {path: '/Recent', name: 'Recent', component: Recent, meta: {title: '最近使用'}},
            {path: '/Personal', name: 'Personal', component: Personal, meta: {title: '个人文档'}},
            {path: '/Department', name: 'Department', component: Department, meta: {title: '部门文档'}},
            {path: '/Group', name: 'Group', component: Group, meta: {title: '群组文档'}},
            {path: '/Public', name: 'Public', component: Public, meta: {title: '公共文档'}},
            {path: '/Examine', name: 'Examine', component: Examine, meta: {title: '审核文档'}},
            {path: '/Recycle', name: 'Recycle', component: Recycle, meta: {title: '回收站'}}
          ]
        },
        {
          path: '/FavouriteTree',
          name: 'FavouriteTree',
          component: FavouriteTree,
          meta: {title: '收藏'},
          redirect: '/FavouriteTreeMenu',
          children: [
            {path: '/FavouriteTreeMenu', name: 'FavouriteTreeMenu', component: FavouriteTreeMenu, meta: {title: '收藏菜单'}},
            {path: '/FavouriteTreeList/:item', name: 'FavouriteTreeList', component: FavouriteTreeList, meta: {title: '收藏文件列表'}}
          ]
        },
        {
          path: '/KnowledgeTree',
          name: 'KnowledgeTree',
          component: KnowledgeTree,
          meta: {title: '知识库'},
          redirect: '/KnowledgeTreeMenu',
          children: [
            {path: '/KnowledgeTreeMenu', name: 'KnowledgeTreeMenu', component: KnowledgeTreeMenu, meta: {title: '知识库菜单'}},
            {path: '/KnowledgeTreeList/:item', name: 'KnowledgeTreeList', component: KnowledgeTreeList, meta: {title: '知识库文件列表'}}
          ]
        },
        {
          path: '/ShareView',
          name: 'ShareView',
          component: ShareView,
          redirect: '/Share',
          children: [
            {path: '/Share', name: 'Share', component: Share, meta: {title: '分享'}},
            {path: '/MyShare', name: 'MyShare', component: MyShare, meta: {title: '我的分享'}},
            {path: '/FriendShare', name: 'FriendShare', component: FriendShare, meta: {title: '好友分享'}}
          ]
        },
        {
          path: '/MyView',
          name: 'MyView',
          component: MyView,
          meta: {title: '我的'},
          redirect: '/My',
          children: [
            {path: '/My', name: 'My', component: My, meta: {title: '我的'}},
            {path: '/MyDetails', name: 'MyDetails', component: MyDetails, meta: {title: '我的账号详情'}},
            {path: '/about', name: 'about', component: about, meta: {title: '关于'}}

          ]
        },
        {
          path: '/Details/:fileId/:type',
          name: 'Details',
          component: Details,
          meta: {title: '详情'},
        },
        {
          path: '/Collection/:resourcesId/:type',
          name: 'Collection',
          component: Collection,
          meta: {title: '收藏夹'},
        },
        {
          path: '/AddKnowledge/:resourcesId/:type',
          name: 'AddKnowledge',
          component: AddKnowledge,
          meta: {title: '知识库'},
        },
        {
          path: '/Search/:currentTreeId',
          name: 'Search',
          component: Search,
          meta: {title: '搜索'},
        }
      ]
    },
    {
      path: '*',
      redirect: '/'
    }
    
    
  ]




const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(from.name)
  // if(from.name != 'Details'){
  //   store.commit('ResetDirectoryId')
  // }
  next()
})

export default router
